package com.goods.business.handler;

import com.goods.common.error.BusinessException;
import com.goods.common.response.ResponseBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author XiaoHong
 * @description 自定义异常处理类
 * @date 2022/2/16
 */
@ControllerAdvice
public class BusinessExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseBean error2(Exception b){
        b.printStackTrace();
        return ResponseBean.error("出错啦");
    }

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResponseBean error(BusinessException b){
        b.printStackTrace();
        return ResponseBean.error(b.getErrorMsg());
    }
}
